package com.xiaoyun.rollutil.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
/**
 * @Author: XiaoYun461
 * @Date: 2021/12/1 18:40
 */
@Slf4j
@Component
public class MetaHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createTime", () -> LocalDateTime.now(), LocalDateTime.class);
        //TODO 等待填充
        this.strictInsertFill(metaObject, "createBy", () -> "admin", String.class);
        //初始化乐观锁
        this.strictInsertFill(metaObject, "version", () -> 0, Integer.class);

    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updateTime", () -> LocalDateTime.now(), LocalDateTime.class);
        //TODO 等待填充
        this.strictUpdateFill(metaObject, "updateBy", () -> "admin", String.class);
    }
}
